const MYSQL = require("../../sql/mysql");
// MYSQL数据库配置信息
const MYSQLConfig = require("../../sql/database");
let sqlName = MYSQLConfig.datasheetName.roles;
/**
 * 删除角色 
 * @param {object} params
 * @param {string} params.id 角色id 
 * @returns {Promise<{code:string,msg:string}>}
 */
module.exports = async (params = {}) => {
  try {
    let { id } = params;
    if (!id) {
      throw { code: 500, msg: "id不能为空" };
    }

    // 删除角色所有菜单权限
    // 删除角色所有操作权限

    // 删除角色
    let query = `DELETE FROM ${sqlName} WHERE id = ${id}`;
    await MYSQL.queryPromise(query);
    return {
      code: 0,
      msg: "删除成功",
    };
  } catch (error) {
    throw error;
  }
};
